package com.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author :admin
 * @description: TODO edit class Description
 * @create date: 2019/8/4 22:27
 */
public class ThreadDemoCreate2 implements Callable {
    @Override
    public Object call() throws Exception {
        for (int i = 0; i < 5; i++) {
            System.out.println(" i = "+i+" "+Thread.currentThread().getName());
        }
        System.out.println("use callable create thread, name:"+Thread.currentThread().getName());
        return "ok";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable oneCallable = new ThreadDemoCreate2();
        FutureTask futureTask1 = new FutureTask(oneCallable);
        FutureTask futureTask2 = new FutureTask(oneCallable);
//     FutureTask是一个包装器，它通过接受Callable来创建，它同时实现了 Future和Runnable接口。
        Thread threadA = new Thread(futureTask1,"threadA");

        threadA.start();
        Thread threadB = new Thread(futureTask2,"threadB");
        threadB.start();
//        System.out.println("result :"+futureTask.get());

    }
}
